package com.ttedu.database.service.Impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ttedu.database.dao.itemsMapper;
import com.ttedu.database.model.items;
import com.ttedu.database.model.itemsExample;
import com.ttedu.database.model.itemsanswers;
import com.ttedu.database.service.ItemsAnswersService;
import com.ttedu.database.service.ItemsChaptertipsService;
import com.ttedu.database.service.ItemsService;
import com.ttedu.database.service.ItemsbankService;

@Service
public class ItemsServiceImpl implements ItemsService{
	@Autowired
	private itemsMapper itemsmapper;
	@Autowired
	private ItemsAnswersService itemsanswersservice;
	@Autowired
	private ItemsbankService itemsbankservice;
	@Autowired
	private ItemsChaptertipsService itemschaptertipsservice;
	/**
	 * 首页查询页
	 * */
	public List<items> selectItemsAll(Map map){
		return itemsmapper.selectItemsAll(map);
	}
	/**
	 * 首页统计页
	 * */
	public int selectItemsCount(Map map){
		itemsExample example=new itemsExample();
		return itemsmapper.countByExample(example);
	}
	//保存一个题
	public void saveItems(items itemone,List<itemsanswers> listitemsanswers,String bankstree,String chaptertipstree){
		itemsmapper.insert(itemone);
		int itemId=itemone.getId();
		System.out.println("itemId="+itemId);
		//添加答案
		itemsanswersservice.addBacthItemsAnswers(listitemsanswers, itemId);
		//添加题目与题库关系
		itemsbankservice.addBatchItemsbank(bankstree, itemId);
		//添加题目与知识点关系
		itemschaptertipsservice.addBatchItemsChaptertips(chaptertipstree, itemId);
	}
}
